<template>
  <div>
    <h3>和为{{ $store.state.countOptios.sum }}</h3>
    <h3>第一个人的名字是:{{OnePersonListName}}</h3>
    <h1>人员列表</h1>
    <input type="text" placeholder="请输入名字" v-model="name">
    <button @click="add">添加</button>
    <button @click="addThree">添加不小于3个字符串</button>
    <ul>
      <li v-for="item in PersonList" :key="item.id">{{ item.id }}---{{ item.name }}</li>
    </ul>
  </div>
</template>

<script>
import {nanoid} from "nanoid";

export default {
  name: "Person",
  computed: {
    PersonList() {
      return this.$store.state.peronOptinos.PersonList
    },
    OnePersonListName(){
      return this.$store.getters["peronOptinos/OnePersonListName"]
    }
  }, data() {
    return {
      name: ""
    }
  },
  methods: {
    add() {
      const personObj = {id: nanoid(), name: this.name}
      this.name = ""
      //this.PersonList.push(personObj)
      this.$store.commit("peronOptinos/ADDPersonList", personObj)
    },
    addThree(){
      const personObj = {id: nanoid(), name: this.name}
      console.log(personObj)
      this.name = ""
      //this.PersonList.push(personObj)
      this.$store.dispatch("peronOptinos/addThree", personObj)
    }
  }

  , mounted() {
    console.log(this.$store)
  }
}
</script>

<style scoped>

</style>